package com.loe.ktui.custom

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import com.loe.ktui.UiGroup
import com.loe.ktui.UiView
import com.loe.ktui.statusHeight

open class UiStatus(id: String? = null) : UiView(id)
{
    /** 创建view */
    override fun createView(context: Context, parent: ViewGroup?): KtStatusView
    {
        return KtStatusView(context).also()
        {
            addToParent(parent, it)
        }
    }
}

fun Any.ui_Status(id: String? = null, block: (UiStatus.() -> Unit)? = null): UiStatus
{
    val ui = UiStatus(id)
    block?.let { ui.it() }
    if (this is UiGroup) addChild(ui)
    return ui
}

open class KtStatusView : View
{
    constructor(context: Context) : super(context)
    {
        initXML()
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    {
        initXML()
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
    {
        initXML()
    }

    private fun initXML(typedArray: TypedArray? = null)
    {
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
    {
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), statusHeight)
    }
}